#!/usr/bin/env python

import os
import pickle
import types

from activist.Config import Config

logdir = os.path.join(Config.base,'data/commands.log')
commands = os.listdir(logdir)
commands.sort()

for commandfile in commands:
    if commandfile == '.svn':
        continue

    try:
        file = open(os.path.join(logdir,commandfile),'r')
        trace = pickle.load(file)
        cmd = pickle.load(file)
        file.close()
    except:
        print "FAILED to load command:",commandfile
        raise

    count = int(commandfile) + 1
    (commandname,version,object,args,kwargs) = cmd
    if len(args) > 2 and type(args[0]) is types.TypeType:
        print count,": create object with ID:",args[1],args[0]
    else:
        print str(count) + ":",commandname,version,object,args,kwargs
